import { createRouter, createWebHistory } from "vue-router";
import { useUserStore } from '@/store/user'


const routes = [
  {
    path: "/",
    name: "Home",
    component: () =>import(/* webpackChunkName: "home" */ "../views/Home.vue"),
  },
  {
    path: "/Course",
    name: "Course",
    component: () =>import(/* webpackChunkName: "about" */ "../views/Course.vue"),
  },
  {
    path: "/CourseInfo/:id",
    name: "CourseInfo",
    component: () =>
      import(/* webpackChunkName: "CourseInfo" */ "../views/CourseInfo.vue"),
  },
  {
    path: "/Login",
    name: "Login",
    component: () =>
      import(/* webpackChunkName: "Login" */ "../views/Login.vue"),
  },
  { 
    path:'/course-play',
    name:'course-play',
    component: () =>
      import(/* webpackChunkName: "CoursePlay" */ "../views/CoursePlay.vue"),
  },
  { 
    path:'/cart',
    name:'Cart',
    component: () =>
      import(/* webpackChunkName: "CoursePlay" */ "../views/Cart.vue"),
    beforeEnter: (to, from, next) => {
      if( useUserStore().token ){
        next()
      }else {
        next('/login')
      }
      
    }
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;